@extends('shared.adminBase')
@section('title','活动管理')
@section('styles')
    <link href="/lightbox/css/lightbox.min.css" rel="stylesheet"/>
@endsection
@section('content')
    <section class="content-header">
        <h1>活动管理</h1>
        <ol class="breadcrumb">
            <li><a href="{{URL::action('AdminController@innerIndex')}}"><i class="fa fa-home"></i> 首页</a></li>
            <li class="active">活动管理</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                <div class="box">
                    <div class="box-header"></div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                            <form id="form1" action="{{URL::action('GameController@getActivityList')}}"
                                  method="get">
                                <input type="hidden" name="page" value="{{$pagerSet->currentPage()}}">
                                <div class="row" style="margin-left: 5px;">
                                    <label>编号：<input class="form-control" name="id"
                                                     value="{{$form->id}}"></label>
                                    <label>名称：<input class="form-control" name="name"
                                                     value="{{$form->name}}"></label>
                                    <button type="submit" class="btn btn-primary">查询</button>
                                    <button type="button" onclick="clearForm('form1');" class="btn btn-primary">清空
                                    </button>
                                </div>
                            </form>
                            <br/>
                            <div class="row col-sm-12">
                                <button class="btn btn-default"
                                        onclick="batchDelete();">
                                    删除
                                </button>
                            </div>
                            <div class="row">
                                <div class="col-sm-12">
                                    <table id="example1" class="table table-bordered table-striped dataTable"
                                           role="grid" aria-describedby="example1_info">
                                        <thead>
                                        <tr role="row">
                                            <th><label><input type="checkbox" id="selectAll" onclick="selectAll(this);">全选</label>
                                            </th>
                                            <th>编号</th>
                                            <th>图片</th>
                                            <th>名称</th>
                                            <th>简介</th>
                                            <th>发布时间</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($pagerSet as $item)
                                            <tr role="row" class="odd">
                                                <td><input type="checkbox" name="activityID"
                                                           value="{{$item->activity_id}}"></td>
                                                <td>{{$item->activity_id}}</td>
                                                <td><a class="example-image-link" href="{{ $item->image_path }}"
                                                       data-lightbox="example-1"><img src="{{$item->image_path}}"
                                                                                      alt="活动图片" title="点击放大"
                                                                                      style="width:50px;height: 30px;"></a>
                                                </td>
                                                <td>{{$item->name}}</td>
                                                <td>{{$item->intro}}</td>
                                                <td>{{$item->publish_date}}</td>
                                                <td>{{App\Framework\Enum\ActivityStatusEnum::getName($item->status)}}</td>
                                                <td><a
                                                            href="{{URL::action('GameController@editActivity',['id'=>$item->activity_id])}}"
                                                            class="btn-xs btn-default">修改</a>
                                                    <a href="javascript:del('{{$item->activity_id}}');"
                                                       class="btn-xs btn-default">删除</a>
                                                    <a href="javascript:setUp('{{$item->activity_id}}');"
                                                       class="btn-xs btn-default"><i
                                                                class="fa fa-arrow-up" title="向上移动"></i></a>
                                                    <a href="javascript:setDown('{{$item->activity_id}}');"
                                                       class="btn-xs btn-default"><i
                                                                class="fa fa-arrow-down" title="向下移动"></i></a></td>
                                            </tr>
                                        @endforeach
                                    </table>
                                </div>
                            </div>
                            <div class="row">
                                @include('shared.tablePaginate')
                            </div>
                            </form>
                        </div>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@endsection


<script type="text/javascript">

    //单个删除
    function del(id) {
        if (confirm('确定要删除该活动吗？') == false) {
            return;
        }

        $.post('{{URL::action('GameController@deleteActivity')}}', {
            'id': id,
            '_token': '{{csrf_token()}}'
        }, function (result) {

            if (result.success) {
                alert('删除成功');
                window.location.reload();
            }
            else {
                alert(result.info);
            }
        });
    }

    function setUp(act_id) {
        $.post('{{URL::action('GameController@setActivitySortUp')}}', {
            'id': act_id,
            '_token': '{{csrf_token()}}'
        }, function (result) {
            if (result.success) {
                window.location.reload();
            } else {
                alert(result.info);
            }
        });
    }

    function setDown(act_id) {
        $.post('{{URL::action('GameController@setActivitySortDown')}}', {
            'id': act_id,
            '_token': '{{csrf_token()}}'
        }, function (result) {
            if (result.success) {
                window.location.reload();
            } else {
                alert(result.info);
            }
        });
    }

    function selectAll(obj) {

        if ($(obj).is(":checked")) {
            $("[name='activityID']").prop('checked', true);
        } else {
            $("[name='activityID']").prop('checked', false);
        }
    }

    function batchDelete() {
        var activityIds = $("input[name='activityID']:checked").serialize();
        if (activityIds.length <= 0) {
            alert('请选择需要删除的活动');
            return false;
        }

        if (!confirm("确定要删除选中的活动吗？")) {
            return false;
        }

        $.post('{{URL::action('GameController@batchDeleteActivity')}}', {
            'activityID': activityIds,
            '_token': '{{csrf_token()}}'
        }, function (result) {
            if (result.success) {
                window.location.reload();
            } else {
                alert(result.info);
            }
        });
    }

</script>
